package com.kfm.controller;

import com.kfm.model.Account;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

//@Controller
//@ResponseBody
@RestController
public class JsonstrController {

    @RequestMapping("/str")
//    @ResponseBody
    public String str(){
        return "hello world";
    }
    @RequestMapping("/json")
//     @ResponseBody
    public Account account(){
        Account account = new Account();
        account.setId(111);
        account.setName("张三");
        account.setUsername("admin");
        account.setPassword("123456");

        return account;
    }

    @RequestMapping("/json2")
//    @ResponseBody
    public List<Account> account2(){
        List<Account> list = new ArrayList<>();
        Account account = new Account();
        account.setId(111);
        account.setName("张三");
        account.setUsername("admin");
        account.setPassword("123456");
        list.add(account);

        Account account2 = new Account();
        account2.setId(222);
        account2.setName("李四");
        account2.setUsername("lsi");
        account2.setPassword("123456");
        list.add(account);
        return list;
    }

    @RequestMapping("/mv4")
    public ModelAndView mv(){
        return new ModelAndView("hello");
    }
}
